package com.iwdm.renovation;

import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.databinding.ActivityChatBinding;

import java.util.ArrayList;
import java.util.List;

public class ChatActivity extends AppCompatActivity {
    ActivityChatBinding binding;
    private List<Chat> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityChatBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        RecyclerView recyclerView = binding.list;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        list = new ArrayList<>();
        list.add(new Chat().setSend(false).setMsg("您好！有什么可以帮你的嘛"));
        MyChatRecyclerViewAdapter myChatRecyclerViewAdapter = new MyChatRecyclerViewAdapter(list);
        recyclerView.setAdapter(myChatRecyclerViewAdapter);
        binding.send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.add(new Chat().setSend(true).setMsg(binding.sendMsg.getText().toString()));
                binding.sendMsg.setText("");
                myChatRecyclerViewAdapter.notifyDataSetChanged();
            }
        });
    }
}
